package wang.aweb.childcar.controller.agentApi;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wang.aweb.childcar.common.ApiRestResponse;
import wang.aweb.childcar.exception.CarException;
import wang.aweb.childcar.exception.CarExceptionEnum;
import wang.aweb.childcar.filter.AgentFilter;
import wang.aweb.childcar.model.pojo.WqPage;
import wang.aweb.childcar.model.query.MemberParam;
import wang.aweb.childcar.model.vo.MemberVO;
import wang.aweb.childcar.service.MemberService;

import java.util.Map;

@RestController
@RequestMapping("/agentApi/member/")
public class AgentMemberController {
    @Autowired
    private MemberService memberService;
    @PostMapping("getList")
    public ApiRestResponse getList(@RequestBody MemberParam memberParam){
        memberParam.setAgentId(AgentFilter.agentThreadLocal.get().getId());
        PageInfo pageInfo =memberService.selectList(memberParam.getPage(),memberParam.getLimit(),memberParam);
        WqPage wqPage=new WqPage(pageInfo.getTotal(),pageInfo.getList());
        return ApiRestResponse.success(wqPage);
    }
    @PostMapping("disableorEnable")
    public ApiRestResponse disableOrEnable(@RequestBody Map reqMap){
        memberService.disableOrEnable((int)reqMap.get("id"));
        return ApiRestResponse.success();
    }
    @PostMapping("addMoney")
    public ApiRestResponse addMoney(@RequestBody Map reqMap){
        if (StringUtils.isEmpty(reqMap.get("addMoney").toString())) {
            throw new CarException(CarExceptionEnum.MONEY_NOT_NULL);
        }
        Integer id=Integer.valueOf((String) reqMap.get("id"));
        Integer addMoney=Integer.valueOf((String)reqMap.get("addMoney"));
        memberService.sysAddMoney(id,addMoney);
        return ApiRestResponse.success();
    }
}
